#include "u8g2PageMain.h"
#include "env.h"
#include "u8g2Common.h"
#include "stdio.h"
BOOL u8g2PageMain(u8g2_t *u8g2, U8g2PageMainParms *parms)
{
    char strTmp[16];
    drawTitle(u8g2, 16, 16, env.chargerMode);
    drawFastChargeLogo(u8g2, 40, 16);
    drawWait(u8g2, 54, 16);
    // 电压展示
    sprintf(strTmp, "%.2f V", parms->batteryVoltage);
    u8g2_SetFont(u8g2, u8g2_font_spleen8x16_mu);
    u8g2_DrawStr(u8g2, 128 - u8g2_GetStrWidth(u8g2, "BATTERY") - 4, 16, "BATTERY");
    u8g2_DrawStr(u8g2, 128 - u8g2_GetStrWidth(u8g2, strTmp) - 4, 32, strTmp);
    sprintf(strTmp, "%.2f A", parms->batteryCurrent);
    u8g2_DrawStr(u8g2, 128 - u8g2_GetStrWidth(u8g2, strTmp) - 4, 48, strTmp);

    if (parms->totalChargedmAH > 999)
    {
        if (parms->totalChargedmAH > 9999)
        {
            sprintf(strTmp, "%.1f AH", parms->totalChargedmAH / 1000.0);
        }
        else
        {
            sprintf(strTmp, "%.2f AH", parms->totalChargedmAH / 1000.0);
        }
    }
    else
    {
        sprintf(strTmp, "%lu MAH", parms->totalChargedmAH);
    }

    u8g2_DrawStr(u8g2, 128 - u8g2_GetStrWidth(u8g2, strTmp) - 4, 64, strTmp);

    u8g2_SetFont(u8g2, u8g2_font_spleen16x32_mu);
    if (parms->chargeStatus == E_U8G2_CHARGE_STATUS_FULL)
    {
        u8g2_DrawStr(u8g2, 32 - (u8g2_GetStrWidth(u8g2, "FULL") / 2), 60, "FULL");
    }
    else if (parms->chargeStatus == E_U8G2_CHARGE_STATUS_INCHARGE)
    {
        u8g2_DrawStr(u8g2, 32 - (u8g2_GetStrWidth(u8g2, "CHRG") / 2), 60, "CHRG");
    }
    else if (parms->chargeStatus == E_U8G2_CHARGE_STATUS_NOT_IN_CHARGE)
    {
        u8g2_DrawStr(u8g2, 32 - (u8g2_GetStrWidth(u8g2, "IDLE") / 2), 60, "IDLE");
    }
    else if (parms->chargeStatus == E_U8G2_CHARGE_STATUS_HEAT)
    {
        u8g2_DrawStr(u8g2, 32 - (u8g2_GetStrWidth(u8g2, "OVH!") / 2), 60, "OVH!");
    }

    return FALSE;
}
